<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="org.jbpm.JbpmContext"%>
<%@page import="org.jbpm.JbpmConfiguration"%>
<%@page import="org.jbpm.db.GraphSession"%>
<%@page import="org.jbpm.graph.def.ProcessDefinition"%>
<%@page import="org.jbpm.graph.exe.ProcessInstance"%>
<%@page import="org.hibernate.Criteria"%>
<%@page import="org.hibernate.Session"%>
<%@page import="org.hibernate.criterion.Restrictions"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>    
    <title> 任务列表  </title>   

  </head>
  
  <body>
  <form action="listProcessInstances.jsp" method="post">
		<table width="90%" cellspacing="1" bgcolor="#6495ED">
			<tr bgcolor="white">
				<th >
					流程名称：<input type="text" name="pdName" >
					实例ID：<input type="text" name="pdid" >
					<!-- 启动人：<input type="text" name="startUser" > -->
					<input type="submit" value="查询" >
				</th>
			</tr>
		</table>
	</form>
  	<%
  	JbpmContext ctx = JbpmConfiguration.getInstance().createJbpmContext();
  	
  	String pdid = request.getParameter("pdid");
  	String pdName = request.getParameter("pdName");
  	String startUser = request.getParameter("startUser");
  	
  	//List list = ctx.getGraphSession().findProcessInstances(Long.parseLong(pdid));
  	Session hsession = ctx.getSession();
  	Criteria crit = hsession.createCriteria(ProcessInstance.class);
  	if(pdid!=null &&!"".equals(pdid)){
  		crit.add(Restrictions.eq("id",Long.parseLong(pdid)));
  	}
  	if(pdName!=null &&!"".equals(pdName)){
  		crit.createAlias("processDefinition","pd").add(Restrictions.like("pd.name","%"+pdName+"%"));
  	}
  	//if(startUser!=null &&!"".equals(startUser)){
  	//	crit.add(Restrictions.eq("id"),Long.parseLong(pdid))
  	//}
  	List list = crit.list();
  	pageContext.setAttribute("processInstance",list);
  	
  	 %>
  	 <c:if test="${empty processInstance}">
  	 	没有流程实例
  	 </c:if>
  	  <c:if test="${!empty processInstance}">  	 	
	  	 <table width="90%" cellspacing="1" bgcolor="#6495ED">
	  	 	<tr bgcolor="#2F4F4F">
	  	 		<th><font color="white">实例ID</font></th>
	  	 		<th><font color="white">开始时间</font></th>
	  	 		<th><font color="white">结束时间</font></th>
	  	 		<th><font color="white">流程跟踪</font></th>
	  	 	</tr>
	  	 	
	  	 	<c:forEach items="${processInstance}" var="pi" varStatus="s">
	  	 		<tr bgcolor="white">
	  	 			<td>${pi.id }</td>
	  	 			<td>${pi.start }</td>
	  	 			<td>${pi.end }</td>
	  	 			<td><a href="${pageContext.request.contextPath }/processInstanceImage.jsp?tokenId=${pi.rootToken.id}">流程跟踪</a></td>
	  	 		</tr>	  	 		
	  	 	</c:forEach>
	  	 </table>  	 
  	 </c:if>
  </body>
</html>
